package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DataDictionary;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDataDictionaryService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("dataDictionary")
public class DataDictionaryController {

    @Autowired
    private IDataDictionaryService service;

    @RequestMapping("")
    public String index() {
        return "dataDictionary/list";
    }

    @ResponseBody
    @RequestMapping("list")
    public PageResult list(QueryObject qo) {
        return service.query(qo);
    }
    
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(DataDictionary entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(DataDictionary entity) {
        JsonResult result = new JsonResult();
        try {
            service.update(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑操作失败");
        }
        return result;
    }
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑操作失败");
        }
        return result;
    }
}
